package cn.bdqn.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.bdqn.dao.BillDao;
import cn.bdqn.pojo.Bill;
import cn.bdqn.util.PageBean;
@Service
public class BillServiceImpl implements BillService {
	
	@Autowired
	private BillDao billDao;

	@Override
	public PageBean<Bill> findByPage(int pageNo, int pageSize, String queryProductName, Integer queryProviderId,
			Integer queryIsPayment) {
		// TODO Auto-generated method stub
		PageBean<Bill> pageBean=new PageBean<Bill>();
		pageBean.setPageSize(pageSize);
		int totalCount=billDao.getCountByConditions(queryProductName, queryProviderId, queryIsPayment);
		pageBean.setTotalCount(totalCount);
		pageBean.setPageNo(pageNo);
		int form=(pageBean.getPageNo()-1)*pageBean.getPageSize();
		List<Bill> pageList=billDao.findByPageConditions(form, pageSize, queryProductName, queryProviderId, queryIsPayment);
		pageBean.setPageList(pageList);
		return pageBean;
	}

	@Override
	public Bill findByCode(String billCode) {
		// TODO Auto-generated method stub
		return billDao.findByCode(billCode);
	}

	@Override
	public boolean updateByBill(Bill bill) {
		// TODO Auto-generated method stub
		int result=billDao.updateByBill(bill);
		if(result>0){
			return true;
		}else{
			return false;
		}	
	}

	@Override
	public boolean addBill(Bill bill) {
		// TODO Auto-generated method stub
		int result=billDao.addBill(bill);
		if(result>0){
			return true;
		}else{
			return false;
		}	
	}

	@Override
	public boolean checkBillCode(String billCode) {
		// TODO Auto-generated method stub
		Bill bill=billDao.findByCode(billCode);
		if(bill!=null){
			return true;
		}else{
			return false;
		}	
	}

	@Override
	public int deleteByCode(String billCode) {
		// TODO Auto-generated method stub
		int result=billDao.deleteByCode(billCode);
		return result;
	}

}
